<?php

namespace app\admin\model;

use think\Model;

class Storejoin extends Model
{
    protected $connection = 'database.cheat';
    // 表名
    protected $table = 'store_join';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'store_type_text',
        'store_status_text',
        'reason_is_see_text',

        'agreement_text',
        'store_time_text'
    ];
    

    
    public function getStoreTypeList()
    {
        return ['1' => __('Store_type 1'),'2' => __('Store_type 2')];
    }     

    public function getStoreStatusList()
    {
        return ['1' => __('Store_status 1'),'2' => __('Store_status 2')];
    }     

    public function getReasonIsSeeList()
    {
        return ['1' => __('Reason_is_see 1'),'2' => __('Reason_is_see 2')];
    }     



    public function getAgreementList()
    {
        return ['1' => __('Agreement 1'),'2' => __('Agreement 2')];
    }     


    public function getStoreTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['store_type']) ? $data['store_type'] : '');
        $list = $this->getStoreTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStoreStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['store_status']) ? $data['store_status'] : '');
        $list = $this->getStoreStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getReasonIsSeeTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['reason_is_see']) ? $data['reason_is_see'] : '');
        $list = $this->getReasonIsSeeList();
        return isset($list[$value]) ? $list[$value] : '';
    }





    public function getAgreementTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['agreement']) ? $data['agreement'] : '');
        $list = $this->getAgreementList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStoreTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['store_time']) ? $data['store_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setStoreTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
